package com.example.xiaoxueqixiangmu.jiemian;

import android.content.ContentValues;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.xiaoxueqixiangmu.R;

import java.sql.SQLTransactionRollbackException;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Create By Visen
 * Date: 2021/8/31
 */
public class HistoryAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<HashMap<String,String>> dataArray ;

    public HistoryAdapter(Context context , ArrayList<HashMap<String,String>> dataArray){
        this.context = context;
        this.dataArray = dataArray;
    }

    @Override
    public int getCount() {
        return dataArray.size();
    }

    @Override
    public Object getItem(int position) {
        return dataArray.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        View item = layoutInflater.inflate(R.layout.item_history, null, false);
        TextView txtGoCity = item.findViewById(R.id.txtGoCity);
        TextView txtBackCity = item.findViewById(R.id.txtBackCity);

        HashMap<String, String> hashMap = dataArray.get(position);
        txtBackCity.setText(hashMap.get("backCity"));
        txtGoCity.setText(hashMap.get("goCity"));
        return item;
    }
}
